package com.runen.wnhz.runen.presenter.iPresenter;

import com.runen.wnhz.runen.data.entity.MyCollection;
import com.runen.wnhz.runen.presenter.BasePresenter;
import com.runen.wnhz.runen.presenter.Contart.MyCollectionContract;
import com.runen.wnhz.runen.presenter.model.MyCollectionModel;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 描述：
 * 作者： 天天童话丶
 * 时间： 2018/6/2.
 */

public class IMyCollectionPersenter extends BasePresenter<MyCollectionModel, MyCollectionContract.View> {

    @Inject
    public IMyCollectionPersenter(MyCollectionModel mModel, MyCollectionContract.View mView) {
        super(mModel, mView);
    }

    //获取我的收藏

    public void getCollectionList(){
        Map<String,String> map = new HashMap<>();
        map.put("token", mView.getToken());
        map.put("page",mView.getPage());

        mModel.getCollectionList(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<MyCollection>() {
                    @Override
                    public void call(MyCollection myCollection) {
                        switch (myCollection.getRe()){
                            case "-1":
                                mView.onTokenError(myCollection.getInfo());
                                break;
                            case "0":
                                mView.showErrorMessage(myCollection.getInfo());
                                break;
                            case "1":
                                mView.onSuccess(myCollection.getData());
                                break;
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        mView.showErrorMessage(throwable.getMessage());
                    }
                });
    }
}
